//The purpose of this class is to allow the user to browse through the intake options.
package com.mckillion.icare;

//Import the java classes required
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.mckillion.icare.R;

//The class extends activity which allows the Android features to be imported.
public class IntakeScreen extends Activity{
	//Declare the variables required for this class.
	//private variables are used to promote consistency.
	private Button bfastButton, lunchButton, dinnerButton, snackButton;
	private ImageView infoButton;
	private TextView infoText;
	private ImageButton homeButton, backButton, settingsButton;
	
	//overwrite the onCreate method so that variables are instantiated on opening.
	public void onCreate(Bundle savedInstanceState) {
        //Call to the super class.
		super.onCreate(savedInstanceState);
        
		//Remove title and notification bars to give it an android feel.
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        
		//Set the content layout to the main_screen XML file.
        setContentView(R.layout.intake_screen);
        
    	//make the objects match the objects in the layout file.
        homeButton=(ImageButton)findViewById(R.id.home_button);
        backButton=(ImageButton)findViewById(R.id.back_button);
        settingsButton=(ImageButton)findViewById(R.id.settings_button);
        bfastButton=(Button)findViewById(R.id.bfast_button);
        lunchButton=(Button)findViewById(R.id.lunch_button);
        dinnerButton=(Button)findViewById(R.id.dinner_button);
        snackButton=(Button)findViewById(R.id.snack_button);
        infoButton=(ImageView)findViewById(R.id.imageView4);
        
        //Set a listener for the information button
        infoButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				//Use a layout inflater to open a pop-up window with the informational text.
				LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);  
				View popupView = layoutInflater.inflate(R.layout.info_popup, null);  
			    final PopupWindow popupWindow = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT,  LayoutParams.WRAP_CONTENT);
			    
			    infoText = (TextView) popupWindow.getContentView().findViewById(R.id.info_text);
			    infoText.setText("This is the intake home screen." + "\n" + "\n" +
			    					"Choose a meal that you wish to input." + "\n" + "\n" +
			    					"Historical data can be found by navigating to the history screen. " +
			    					"The history screen is available through the home page." + "\n" + "\n" +
			    					"Press dismiss to close this message.");
			    
			    //create a dismiss button to close the pop-up window.
			    Button dismiss = (Button)popupView.findViewById(R.id.dismiss_button);
	            dismiss.setOnClickListener(new Button.OnClickListener(){
	            	@Override
	            	public void onClick(View v) {
	            		popupWindow.dismiss();
	            	}});
	               
	            //Put the pop-up window in the centre of the screen
	            popupWindow.showAtLocation(infoButton, Gravity.CENTER, 0, 0);
	   }});
        
        
        //Set a listener for the home button which starts the HomeScreen class
        homeButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent i = new Intent(IntakeScreen.this, HomeScreen.class);
				startActivity(i);
			}
		});
        
        //Set a listener for the back button which starts the HomeScreen class
        backButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent i = new Intent(IntakeScreen.this, HomeScreen.class);
				startActivity(i);
			}
		});
        
        //Set a listener for the settings button which starts the Settings class
        settingsButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent i = new Intent(IntakeScreen.this, Settings.class);
				startActivity(i);
			}
		});
        
        //Set a listener for the breakfast button which starts the BreakfastScreen class
        bfastButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				bfastButton.setBackgroundResource(R.drawable.buttonpressed);
				Intent i = new Intent(IntakeScreen.this, BreakfastScreen.class);
				startActivity(i);
			}
		});
        
        //Set a listener for the lunch button which starts the LunchScreen class
        lunchButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				lunchButton.setBackgroundResource(R.drawable.buttonpressed);
				Intent i = new Intent(IntakeScreen.this, LunchScreen.class);
				startActivity(i);
			}
		});
        
        //Set a listener for the dinner button which starts the DinnerScreen class
        dinnerButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				dinnerButton.setBackgroundResource(R.drawable.buttonpressed);
				Intent i = new Intent(IntakeScreen.this, DinnerScreen.class);
				startActivity(i);
			}
		});
        
        //Set a listener for the snack button which starts the SnackScreen class
        snackButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				snackButton.setBackgroundResource(R.drawable.buttonpressed);
				Intent i = new Intent(IntakeScreen.this, SnackScreen.class);
				startActivity(i);
			}
		});
        
	}
	
	@Override
	public void onBackPressed() {
		//handle the back button being pressed
		Intent i = new Intent(IntakeScreen.this, HomeScreen.class);
		startActivity(i);
	}
}
